package vcp.gui.forms;

import java.awt.event.ActionListener;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JTextField;

import vcp.common.IView;
import vcp.gui.components.VCPPanel;
import vcp.gui.forms.validators.NumericValidator;

import javax.swing.JLabel;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JButton;




import java.awt.Color;
import java.util.Observable;
import java.util.Observer;


public class CancelOrderForm extends VCPPanel implements Observer,IView {

	private JTextField textOrderID;
	private JButton btnCancelOrder;
	private JLabel lblCancellOrderError;

	/**
	 * Create the panel.
	 */
	public CancelOrderForm() {
		setBackground(Color.WHITE);
		
		lblCancellOrderError = new JLabel("");
		lblCancellOrderError.setForeground(Color.RED);
		JLabel lblOrderID = new JLabel("Order ID");
		textOrderID = new JTextField();
		textOrderID.setColumns(10);

		btnCancelOrder = new JButton("cancellation");
		

		GroupLayout groupLayout = new GroupLayout(this);
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addContainerGap()
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addComponent(lblOrderID)
						.addComponent(lblCancellOrderError))
					.addGap(22)
					.addComponent(textOrderID, GroupLayout.PREFERRED_SIZE, 350, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(btnCancelOrder)
					.addContainerGap(18, Short.MAX_VALUE))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(18)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
							.addComponent(lblOrderID)
							.addComponent(textOrderID, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
							.addComponent(btnCancelOrder))
						.addComponent(lblCancellOrderError))
					.addContainerGap(268, Short.MAX_VALUE))
		);
		setLayout(groupLayout);
	}
	
	
	

	@Override
	public void addController(Object obj) {
		btnCancelOrder.addActionListener((ActionListener)obj);
		btnCancelOrder.setActionCommand("cancelOrder");
	}

	@Override
	public void update(Observable o, Object arg) {
		//if(arg.toString().equals("cancelOrderOK"))
			   System.out.println(arg);	
		
	}




	public JTextField getTextOrderID() {
		return textOrderID;
	}




	public void setTextOrderID(JTextField textOrderID) {
		this.textOrderID = textOrderID;
	}




	public JButton getBtnCancelOrder() {
		return btnCancelOrder;
	}




	public void setBtnCancelOrder(JButton btnCancelOrder) {
		this.btnCancelOrder = btnCancelOrder;
	}




	public JLabel getLblCancellOrderError() {
		return lblCancellOrderError;
	}




	public void setLblCancellOrderError(JLabel lblCancellOrderError) {
		this.lblCancellOrderError = lblCancellOrderError;
	}

	/*
	private void actionPerformedHandle(ActionEvent e) {
		
		String ID = textOrderID.getText();// get the text box from gui
		Orders bean; // order to send
		OrderController orderControl; // cretae order controller
		NumericValidator verifyID = new NumericValidator(); // create validator
															// to cheack the id

		if (!verifyID.validate(ID)) { // wrong input
			JOptionPane.showMessageDialog(null,
					"Invalid ID Entered,Please Re-Enter",
					"Invalid Input Error", JOptionPane.ERROR_MESSAGE);
		} else { // good input
			try {
				orderControl = new OrderController(client);
				bean = new Orders();
				bean.setOid(Integer.parseInt(ID));
				System.out.println("order_created");
				orderControl.CancelOrder(bean);
			} catch (Exception e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}

		}
	}
	*/
}